package com.huawei.zyb.taskManager.domain.requirement.valueobject;

/**
 * 文档类型枚举
 */
public enum DocumentType {
    SPECIFICATION("需求规格说明", "spec"),
    DESIGN("设计文档", "design"),
    PROTOTYPE("原型设计", "prototype"),
    REFERENCE("参考资料", "reference"),
    API_DOC("API文档", "api"),
    USER_MANUAL("用户手册", "manual"),
    TECHNICAL_DOC("技术文档", "tech"),
    OTHER("其他", "other");

    private final String description;
    private final String code;

    DocumentType(String description, String code) {
        this.description = description;
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public String getCode() {
        return code;
    }

    /**
     * 根据代码获取文档类型
     */
    public static DocumentType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return OTHER;
        }
        
        for (DocumentType type : values()) {
            if (type.code.equals(code.trim().toLowerCase())) {
                return type;
            }
        }
        return OTHER;
    }

    /**
     * 根据描述获取文档类型
     */
    public static DocumentType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return OTHER;
        }
        
        for (DocumentType type : values()) {
            if (type.description.equals(description.trim())) {
                return type;
            }
        }
        return OTHER;
    }

    /**
     * 检查是否为技术类文档
     */
    public boolean isTechnicalDocument() {
        return this == DESIGN || this == API_DOC || this == TECHNICAL_DOC;
    }

    /**
     * 检查是否为用户相关文档
     */
    public boolean isUserDocument() {
        return this == SPECIFICATION || this == PROTOTYPE || this == USER_MANUAL;
    }

    @Override
    public String toString() {
        return description;
    }
}